<?php
session_start();
include('lib/lib.php');
include('connado.php');
//include('authen.php');
header("Content-type: text/html; charset=utf-8");
$logfile = PAHTLOG."ajax_cmdexchname-" . date("Y-m-d") . ".log";


$location_id = $_REQUEST['location_id'];
$exch_name = $_REQUEST['exch_name'];
$province_id = $_REQUEST['province_id'];
$action = $_REQUEST['action'];

writelog($logfile, "location_id num     : " . $location_id);
writelog($logfile, "exch_name      : " . $exch_name);
writelog($logfile, "province_id      : " . $province_id);
$exch_name = iconv('tis-620', 'utf-8', $exch_name);
writelog($logfile, "action   : " . $action);

if($action == "add"){
	$sql = "insert into exchange(location_id, exch_name, province_id)values(?, ?, ?)";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($location_id, $exch_name, $province_id);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "add exchnage success!");
	}else{
		writelog($logfile, "add exchnage error!");
	}
}else if($action == "del"){
	$sql = "delete from exchange where location_id=?";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($location_id);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "delete exchnage success!");
	}else{
		writelog($logfile, "delete exchnage error!");
	}
}else if($action == "edit"){
	$sql = "update exchange set exch_name =?,province_id=?  where location_id=?";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($exch_name, $province_id, $location_id);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "update exchange success!");
	}else{
		writelog($logfile, "update exchange error!");
	}
	
}


writelog($logfile, "reply : OK");
writelog($logfile, "-------------------------------------------------- ");
echo viewExchName($db);

?>

